/* recognize tokens for the translator */
%option noyywrap yylineno
%{
   #include "parser.tab.h"
   #include<stdio.h>
   #include<stdarg.h>
   #include<string.h>
   void yyerror(char *s, ...);
   /*extern  "C"
   {*/
     extern int yylex(void);

   /*}*/
%}

%%

"sorts"[ \r\t]*"definition"[ \r\t]*\n {yylval.intval=1;return SORTDEFKEYWORD;}
"predicates"[ \r\t]*"declaration"[ \r\t]*\n {yylval.intval=2;return PREDDEFKEYWORD;}
"program"[ \r\t]*"rules"[ \r\t]*\n {yylval.intval=3;return PROGRULDEFKEYWORD;}
[a-z][a-zA-Z0-9_]*[ \t\r\n]*"("     {yylval.str=strdup(yytext); return IDENTIFIER_WITH_OP; }
"-"[a-z][a-zA-Z0-9_]*[ \t\r\n]*"("     {yylval.str=strdup(yytext); return NEGATIVE_ATOM_WITH_OP; }
[a-z][a-zA-Z0-9_]*         {yylval.str=strdup(yytext);  return IDENTIFIER; }
"not"[ \t\r]+   {yylval.str=strdup(yytext);  return NOT; }
[A-Z][a-zA-Z0-9_]*         {yylval.str=strdup(yytext);  return VARIABLE; }
[1-9][0-9]*               {yylval.str=strdup(yytext);  return POSITIVE_INTEGER;}
"0"                       {yylval.str=strdup(yytext);  return ZERO;}
"+"                       {yylval.str=strdup(yytext);  return PLUS;}
"-"                       {yylval.str=strdup(yytext);  return MINUS;}
"*"                       {yylval.str=strdup(yytext);  return MULT; }
"/"                       {yylval.str=strdup(yytext);  return DIV; }
"="                       {yylval.str=strdup(yytext);  return EQ;   }
"!="                      {yylval.str=strdup(yytext);  return NOTEQ;}
">"                       {yylval.str=strdup(yytext);  return GT;}
"%"                       {yylval.str=strdup(yytext);  return MOD;  }
">="                      {yylval.str=strdup(yytext);  return GTEQ;}
"<"                       {yylval.str=strdup(yytext);  return SM;}
"<="                      {yylval.str=strdup(yytext);  return SMEQ;}
"("                       {yylval.str=strdup(yytext);  return OP; }
")"                       {yylval.str=strdup(yytext);  return CP; }
":-"                      {yylval.str=strdup(yytext);  return ORRSEP;}
":+"                      {yylval.str=strdup(yytext);  return CRRSEP;}
","                       {yylval.str=strdup(yytext);  return COMMA;}
"."                       {yylval.str=strdup(yytext);  return DOT;}
":"                       {yylval.str=strdup(yytext);  return COLON;}
"//".*  /* ignore comments */
[ \t\r\n]   { /* ignore white space and newline */ }
<<EOF>>                   {  yyterminate(); }
.	{ yyerror("Mystery character %c\n", *yytext); }
%%

void
yyerror(char *s, ...)
{
  va_list ap;
  va_start(ap, s);
  fprintf(stderr, "%d: error: ", yylineno);
  vfprintf(stderr, s, ap);
  fprintf(stderr, "\n");
}
